package org.jeecg.modules.flower.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.flower.entity.FlowerLose;
import org.jeecg.modules.flower.entity.FlowerLoseInfo;
import org.jeecg.modules.flower.entity.FlowerTagInfo;
import org.jeecg.modules.flower.entity.FlowerTagpre;
import org.jeecg.modules.flower.mapper.FlowerLoseInfoMapper;
import org.jeecg.modules.flower.mapper.FlowerLoseMapper;
import org.jeecg.modules.flower.service.IFlowerLoseInfoService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Description: 蔬菜货损详情
 * @Author: jeecg-boot
 * @Date:   2022-06-29
 * @Version: V1.0
 */
@Service
public class FlowerLoseInfoServiceImpl extends ServiceImpl<FlowerLoseInfoMapper, FlowerLoseInfo> implements IFlowerLoseInfoService {

    @Override
    public Page<FlowerTagpre> getFlowerTagPre(String flowerLoseId, Integer pageNo, Integer pageSize,FlowerLose flowerLose) {
        QueryWrapper<FlowerLoseInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("flower_lose_id",flowerLoseId);
        long count = count(queryWrapper);
        int start=(pageNo-1)*pageSize;
        int end=start+pageSize;
        if(end > count){
            end = (int) count;
        }
        List<FlowerTagpre> pageData = baseMapper.getFlowerTagPre(flowerLoseId,start,end,flowerLose);
        Page<FlowerTagpre> page = new Page<>();
        page.setTotal(count);
        page.setCurrent(pageNo);
        page.setSize(pageSize);
        page.setRecords(pageData);
        return page;
    }

    @Override
    public Page<FlowerTagInfo> getFlowerTag(String flowerLoseId, Integer pageNo, Integer pageSize,FlowerLose flowerLose) {
        QueryWrapper<FlowerLoseInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("flower_lose_id",flowerLoseId);
        int count = (int) count(queryWrapper);
        int start=(pageNo-1)*pageSize;
        int end=start+pageSize;
        if(end > count){
            end = count;
        }
        List<FlowerTagInfo> pageData = baseMapper.getFlowerTag(flowerLoseId,start,end,flowerLose);
        Page<FlowerTagInfo> page = new Page<>();
        page.setTotal(count);
        page.setCurrent(pageNo);
        page.setSize(pageSize);
        page.setRecords(pageData);
        return page;
    }
}
